package com.start.shop.api.vo.goods;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.start.shop.modules.repository.entity.Goods;
import com.start.shop.modules.repository.entity.Sku;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
public class GoodsVo {
	private int goodsId;
    private int goodsType;
	private String goodsName;
	private String goodsTitle;
	private int saleCnt;
	private String goodsImg;
	private BigDecimal marketLowPrice;
	private BigDecimal skuLowPrice;
	private BigDecimal marketHighPrice;
	private BigDecimal skuHighPrice;
	private BigDecimal pointLowPrice;
	private BigDecimal pointHighPrice;
	private List<String> bannerImg;
	private List<String> goodsDesc;
	private int buyLimit;
	
	public GoodsVo() {
		super();
	}
	
	public static GoodsVo setdata(Goods goods, List<Sku> skuList) {
		
		GoodsVo goodsVo = new GoodsVo();
		goodsVo.setGoodsId(goods.getGoodsId());
		goodsVo.setGoodsType(goods.getGoodsType());
		goodsVo.setGoodsImg(goods.getGoodsImg());
		goodsVo.setGoodsName(goods.getGoodsName());
		goodsVo.setGoodsTitle(goods.getGoodsTitle());
		goodsVo.setSaleCnt(goods.getSaleCnt());
		goodsVo.setGoodsImg(goods.getGoodsImg());
		goodsVo.setBannerImg(Arrays.asList(goods.getBannerImg().split(",")));
		goodsVo.setGoodsDesc(Arrays.asList(goods.getGoodsDesc().split(",")));
		goodsVo.setBuyLimit(goods.getBuyLimit());

		List<BigDecimal> marketPrice =  skuList.stream().map((p) ->p.getSkuMarketPrice()).collect(Collectors.toList());
		List<BigDecimal> skuPrice =  skuList.stream().map((p) ->p.getSkuPrice()).collect(Collectors.toList());

		goodsVo.setMarketLowPrice( Collections.min(marketPrice));
		goodsVo.setSkuLowPrice( Collections.min(skuPrice));
		
		goodsVo.setMarketHighPrice(Collections.max(marketPrice));
		goodsVo.setSkuHighPrice( Collections.max(skuPrice));
		

		return goodsVo;	
	}
	
	
	
}
